package Pieces;

import java.awt.Point;
import java.awt.geom.Point2D;

public abstract class Piece {
    
	//TODO: Needs to be changed to the correct position
	private Point INIT_POS = new Point(4, 0);
	
	protected static enum PieceState {
		DEFAULT(0), FIRST(1), SECOND(2), THIRD(3);
		
		private final int index;
		
		private PieceState(final int index) {
			this.index = index;
		}
		
		int getIndex() {
			return index;
		}
		
		static PieceState getStateByIndex(int i) {
			for(PieceState s : PieceState.values()) {
				if (s.getIndex() == i) {
					return s;
				}
			}
			return DEFAULT;
		}
	}
	
	protected PieceState currentState;
	protected Point position;

    public Piece() {
		currentState = PieceState.DEFAULT;
		position = INIT_POS;
	}
	
	public void changeState() {
		changeStateBy(1);
	}
	
	public void restoreState() {
		changeStateBy(-1);
	}
	
	private void changeStateBy(int i) {
		System.out.print("Change State By " + i + " curr: " + currentState.getIndex());
		int nextState = (currentState.getIndex() + i) % PieceState.values().length;
		if (nextState < 0) nextState = PieceState.values().length-1;
		
		currentState = PieceState.getStateByIndex(nextState);
		
		System.out.println(" new: " + currentState.index);
	}
	
	public abstract BlockType[][] getCurrentBlockArray();
	
	public Point getPosition() {
		return position;
	}
	
	public void setPosition(Point p) {
		position.setLocation(p);
	}

    public void setPosition(int x, int y) {
        position.setLocation(x, y);
    }
}
